package com.xjtu.controller.admin;

import com.github.pagehelper.Page;
import com.xjtu.dto.medicationRecord.MedicationDto;
import com.xjtu.entity.Medication;
import com.xjtu.result.PageResult;
import com.xjtu.result.Result;
import com.xjtu.service.MedicationService;
import com.xjtu.vo.medication.MedicationDetailVo;
import com.xjtu.vo.medication.MedicationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.Email;
import java.util.List;

@RestController
@RequestMapping("/admin/medication")
@Slf4j
@Api(tags = "服药记录接口")
public class MedicationController {

    @Autowired
    MedicationService medicationService;

    @PostMapping
    @ApiOperation("添加服药记录")
    public Result insert(@RequestBody @Valid MedicationDto medicationDto){
        medicationService.insert(medicationDto);
        return Result.success();
    }

    @GetMapping("finish")
    @ApiOperation("获取今天的到期药")
    public Result<PageResult> getTodayFinishMedcation(@RequestParam(required = false, defaultValue = "1") Integer page,
                                                      @RequestParam(required = false, defaultValue = "10")Integer perPage){
        PageResult pageResult = medicationService.getTodayFinish(page, perPage);
        return Result.success(pageResult);
    }

    @GetMapping("lists")
    @ApiOperation("获取今天要吃的药列表/某个人")
    public Result<PageResult> getTodayMedcationByName(@RequestParam(required = false, defaultValue = "1") Integer page,
                                                              @RequestParam(required = false, defaultValue = "10")Integer perPage,
                                                              @RequestParam(required = false, defaultValue = "null") String elderlyName){
        PageResult pageResult = medicationService.getToday(elderlyName, page, perPage);
        return Result.success(pageResult);
    }

    @GetMapping("allLists")
    @ApiOperation("获取服药列表/某人")
    public Result<PageResult> getMedicationList(@RequestParam(required = false, defaultValue = "1") Integer page,
                                                              @RequestParam(required = false, defaultValue = "10")Integer perPage,
                                                              @RequestParam(required = false, defaultValue = "null") String elderlyName){
        PageResult pageResult = medicationService.getMedication(elderlyName, page, perPage);

        return Result.success(pageResult);
    }

    @PutMapping
    @ApiOperation("修改服药记录")
    public Result changeMedcationById(@RequestBody @Valid MedicationDto medicationDto){
        Result result = medicationService.changeById(medicationDto);
        return result;
    }

    @DeleteMapping
    @ApiOperation("删除服药记录")
    public Result deleteMedcationById(@RequestParam Long id){
        Result result = medicationService.deleteById(id);
        return result;
    }


}
